/**************************************************************************
* This file is part of Hawkengine.
*
* Hawkengine is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Hawkengine is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Hawkengine.  If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/

#ifndef _MENU_H_
#define _MENU_H_

/**************************************************************************
* Dependencies
**************************************************************************/
#include "engine/bounds.h"
#include "engine/common.h"
#include "engine/engine.h"
 
/**************************************************************************
* Preprocessing
**************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
 
#define MAX_OPTION_LENGTH 64
#define MAX_MENU_OPTIONS 6
#define MAX_ACTION_ARGS 2
 
/**************************************************************************
* Types
**************************************************************************/
typedef void (*action_func_type)(void**);
typedef struct
{
  char name[MAX_OPTION_LENGTH];
  action_func_type on_select;
  void* select_args[MAX_ACTION_ARGS];
  action_func_type on_next;
  void* next_args[MAX_ACTION_ARGS];
  action_func_type on_prev;
  void* prev_args[MAX_ACTION_ARGS];
} menu_option_type;

typedef struct
{
  char title[MAX_OPTION_LENGTH];
  menu_option_type options[MAX_MENU_OPTIONS + 1];
  int options_count;
  int active_option_idx;
  action_func_type on_render;
  void* render_args[MAX_ACTION_ARGS]; // first render arg will be bounds
} menu_type;

/**************************************************************************
* Variables
**************************************************************************/
extern const bounds_type MENU_BOUNDS;
extern menu_type menu_about;
extern bounds_type menu_bounds;
extern navigation_type menu_nav_forward;
extern navigation_type menu_nav_back;
extern navigation_type menu_nav_up;
extern navigation_type menu_nav_down;

/**************************************************************************
* Static Variables
**************************************************************************/

/**************************************************************************
* Function Prototypes
**************************************************************************/
BOOL menu_active(void);
void menu_close(void);
void menu_goto(void** args);
void menu_init(void);
void menu_on_close(void** args);
void menu_open(void);
void menu_pause(void);
void menu_on_next_level(void** args);
void menu_on_quit(void** args);
void menu_on_reset_level(void** args);
void menu_navigate(navigation_type navigation);
void menu_render(const bounds_type* bounds);
void menu_setup(void);
void menu_toggle_option(navigation_type navigation, const char* option_desc,
                        menu_option_type* option, BOOL* option_value);
void menu_touch_move(const touch_type* touch);
void menu_touch_start(const touch_type* touch);
void menu_touch_stop(const touch_type* touch);
void menu_update(float secs);

/**************************************************************************
* Function Implementations
**************************************************************************/


#ifdef __cplusplus
}
#endif

#endif
